package input;

import com.jme.input.controls.Binding;
import com.jme.input.controls.GameControl;
import com.jme.input.controls.GameControlManager;

/**
 * A simple {@link Binding} that either returns one or zero. Can be used for AI-controllers or other 
 * controllers that always shall be get a value one or zero.
 * 
 * @author Wasserleiche
 */
public class StraightForwardBinding implements Binding {
	
	private static final long serialVersionUID = 1L;
	
	public static final String FORWARD = "forward";
	public static final String BACKWARD = "backward";
	
	public static final GameControlManager manager = new GameControlManager();
	
	public static final StraightForwardBinding forward = new StraightForwardBinding(FORWARD);
	public static final StraightForwardBinding backward = new StraightForwardBinding(BACKWARD);
	
	/** The name of this {@link Binding}. */
	private String name;
	/** The value this {@link Binding} will return. */
	private float value;
	
	/**
	 * Constructs a new StraightForwardBinding and sets the return-value according the the 
	 * given name.
	 * @param name FORWARD, if this {@link Binding} shall always return one. BACKWARD, if it shall 
	 * always shall return zero.
	 */
	public StraightForwardBinding(String name) {
		this.name = name;
		if(name.equals(FORWARD)) value = 1f;
		else if(name.equals(BACKWARD)) value = 0f;
	}
	
	@Override
	public String getName() { return name; }
	
	/**
	 * Returns either one or zero, depending on the name.
	 */
	@Override
	public float getValue() { return value; }
	
	public static GameControl getGameControl(StraightForwardBinding binding) {
		GameControl control = manager.addControl("Control");
		control.addBinding(binding);
		return control;
	}
}